package com.education.api.controller.admin.system;


import com.education.business.service.system.SystemRoleService;
import com.education.common.base.BaseController;
import com.education.common.model.PageInfo;
import com.education.common.util.Result;
import com.education.common.util.ResultCode;
import com.education.model.RoleMenuDto;
import com.education.model.entity.SystemRole;
import com.education.model.request.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 余一
 * @since 2021-09-10
 */
@RestController
@RequestMapping("/system/role")
public class SystemRoleController extends BaseController {
    @Autowired
    private SystemRoleService systemRoleService;

    @GetMapping
    public Result<PageInfo<SystemRole>> list(PageParam pageParam,SystemRole systemRole){
        return Result.success(systemRoleService.listPage(pageParam,systemRole));
    }

    @PostMapping
    public Result saveOrUpdate(@RequestBody @Validated SystemRole systemRole){
        systemRoleService.saveOrUpdate(systemRole);
        return Result.success();
    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable Integer id){
        return Result.success(systemRoleService.deleteById(id));
    }

    @PostMapping("/saveRolePermission")
    public Result saveRolePermission(@RequestBody RoleMenuDto roleMenuDto){
        systemRoleService.saveRolePermission(roleMenuDto);
        return Result.success(ResultCode.SUCCESS,"权限设置成功");
    }

}
